<?php

/*
Plugin Name: Sistem Informasi Alumni Politeknik Kampar
Plugin URI: https://code.google.com/p/logbook-lenny/
Description: Sistem Informasi Alumni Politeknik Kampar ini bersumber dari progam Pendataan SMA oleh DISDIKPORA <a href="http://kamparkab.go.id">Kabupaten Kampar</a>, dibuat oleh Leni Rapika Oktapiani sebagai Tugas Akhir di <a href="http://tif.poltek-kampar.ac.id">Teknik Informatika</a> <a href="http://poltek-kampar.ac.id">Politeknik Kampar</a>.
Author: Leni Rapika Oktapiani
Version: 1.0.0
Author URI: https://code.google.com/u/114844818880194934018/

*/

/** Jika dipanggil langsung dari http, bukan sebagai plugin, maka
  langsung tewas.
  (Perlindungan dari hacker yang mengakses langsung ke file ini, misal:
  ke /wp-content/plugins/logbook-lenny/
*/
if(!function_exists('add_action'))die('Maaf, jangan dijalankan langsung ya ...!');

/*
#####=====#####=====#####=====#####=====#####=====#####=====
#####=====#####=====#####=====#####=====#####=====#####=====
 ADMIN MENU
#####=====#####=====#####=====#####=====#####=====#####=====
#####=====#####=====#####=====#####=====#####=====#####=====
*/

//saat wordpress memanggil fungsi admin_menu, panggil juga fungsi kita pendataan_create_menu
add_action( 'admin_menu', 'data_menu' );

function data_menu() {

  //create custom top-level menu
  //add_menu_page( page_title, menu_title, capability, menu_slug, function, icon_url, position );
  //  page_title  �   The title of the page as shown in the    <title>   tags
  //  menu_title  �   The name of your menu displayed on the dashboard
  //  capability  �   Minimum capability required to view the menu
  //  menu_slug   �   Slug name to refer to the menu; should be a unique name
  //  function    �   Function to be called to display the page content for the item
  //  icon_url    �   URL to a custom image to use as the Menu icon
  //  position    �   Location in the menu order where it should appear

   
  add_menu_page( 
  	'Data', 					// page_title = judulnya 
  	'Penginputan',			 	//menu_title
	'read',  					//capability
								//agar operator bisa melihat menu ini, jadikan capability nya menjadi read
	__FILE__, 					//menu_slug
	'input_data',				//function // fungsi yang dipanggil saat menu ini diklik
	plugins_url( 'logo.png', __FILE__ ), 	//icon URL
	0 							// position
	);							// 2012-06-06


  //create submenu items
  //add_submenu_page( parent_slug, page_title, menu_title, capability, menu_slug, function );
  
    add_submenu_page( __FILE__, 'Dispora > Data View', 'Data View', 'read', 
	__FILE__.'view_data', 'view_data' );
	



  //Following is a list of all available submenu functions in WordPress.
  //add_dashboard_page  �   Adds a submenu to the Dashboard menu
  //add_posts_page      �   Adds a submenu to the Posts menu
  //add_media_page      �   Adds a submenu to the Media menu
  //add_links_page      �   Adds a submenu to the Links menu
  //add_pages_page      �   Adds a submenu to the Pages menu
  //add_comments_page   �   Adds a submenu to the Comments page
  //add_theme_page      �   Adds a submenu to the Appearance menu
  //add_plugins_page    �   Adds a submenu to the Plugins menu
  //add_users_page      �   Adds a submenu to the Users menu
  //add_management_page �   Adds a submenu to the Tools menu
  //add_options_page    �   Adds a submenu to the Settings menu

  //create a submenu under Settings
  //add_options_page( 'PMB Settings Page', 'PMB', 'manage_options', __FILE__, 'data_sekolah_page' );
}

require_once('input_data.php');
require_once('view_data.php');

//require_once('data_siswa_page.php');

//untuk dashboard widgets yang tampil di halaman utama admin di WordPress
require_once('sisma_dashboard_widgets.php');

/*
#####=====#####=====#####=====#####=====#####=====#####=====
 WIDGETS
 /wp-admin/widgets.php
#####=====#####=====#####=====#####=====#####=====#####=====
*/

// use widgets_init action hook to execute custom function
add_action( 'widgets_init', 'sisma_register_widgets' );
             
 //register our widget
function sisma_register_widgets() {
  register_widget( 'sisma_widgetexample_widget_my_info' );
}


class sisma_widgetexample_widget_my_info extends WP_Widget {
  //process the new widget
  function sisma_widgetexample_widget_my_info() {
      $widget_ops = array(
          'classname' =>  'sisma_widgetexample_widget_class',
          'description' =>  'Display a user\'s favorite movie and song.'
      );
      $this->WP_Widget( 'sisma_widgetexample_widget_my_info', 'PMB Info',
          $widget_ops );
  }

    //build the widget settings form
    function form($instance) {
        $defaults = array( 'title' =>  'My Info', 'movie' =>  '', 'song' =>  '' );
        $instance = wp_parse_args( (array) $instance, $defaults );
        $title = $instance['title'];
        $movie = $instance['movie'];
        $song = $instance['song'];
        ?> 
         <p>Title: <input class="widefat" name="<?php echo $this->get_field_name('title');?>" type="text"
            value="<?php echo esc_attr($title); ?>" /></p> 
         <p>Favorite Movie:  <input class="widefat" name="<?php echo $this->get_field_name( 'movie' ); ?>"  type="text" value=" <?php echo esc_attr( $movie ); ?>" /></p> 
         <p>Favorite Song:   <textarea class="widefat" name="<?php echo $this->get_field_name( 'song' ); ?>" /><?php echo esc_attr( $song ); ?></textarea></p> 
         <?php
    }


  //save the widget settings
  function update($new_instance, $old_instance) {
      $instance = $old_instance;
      $instance['title'] = strip_tags( $new_instance['title'] );
      $instance['movie'] = strip_tags( $new_instance['movie'] );
      $instance['song'] = strip_tags( $new_instance['song'] );
           
      return $instance;
  }
  //display the widget
  function widget($args, $instance) {
    extract($args);
    echo $before_widget;
    $title = apply_filters( 'widget_title', $instance['title'] );
    $movie = empty( $instance['movie'] ) ? ' &nbsp;' : $instance['movie'];
    $song = empty( $instance['song'] ) ? ' &nbsp;' : $instance['song'];

    if ( !empty( $title ) ) { echo $before_title . $title . $after_title; };
    echo ' <p> Fav Movie: ' . $movie . ' </p> ';
    echo ' <p> Fav Song: ' . $song . ' </p> ';
    echo $after_widget;
  }
}




//hook untuk ajax response dari server
//our AJAX server based response


add_action('wp_ajax_sisma_ajax_search','sisma_ajax_search_response');
add_action('wp_ajax_nopriv_sisma_ajax_search','sisma_ajax_search_response');

add_action('wp_ajax_guru_ajax_search','guru_ajax_search_response');
add_action('wp_ajax_nopriv_guru_ajax_search','guru_ajax_search_response');

function sisma_ajax_search_response(){

global $wpdb;
echo '<font size="2">'; 
$posts = Array();
$findme = $_POST['findme'];

$sql = "select * from sekolah where nama_sekolah like '%$findme%';";

$posts = $wpdb->get_results($sql);
echo '<table class="wp-list-table widefat fixed" >
<thead><tr><th style="width: 5px">No</th>
	<th style="width: 5px">NSS</th>
	<th style="width: 15px">Nama Sekolah</th>
	<th style="width: 25px">Alamat</th>
	<th style="width: 10px">Status</th>
	<th style="width: 15px">Desa</th>
	<th style="width: 20px">Kecamatan</th>
	<th style="width: 10px">Kode Pos</th>
	<th style="width: 15px">Kota</th>
	<th style="width: 20px">Provinsi</th>
	<th style="width: 18px">Telepon</th>
	<th style="width: 10px">No Fax</th>
	<th style="width: 20px">Email</th>
	<th style="width: 18px">Website</th>
	<th style="width: 15px">Siswa Kelas X</th>
	<th style="width: 15px">Siswa Kelas XI</th>
	<th style="width: 15px">Siswa Kelas XII</th>
	<th style="width: 15px">Rombel Kelas X</th>
	<th style="width: 15px">Rombel Kelas XI IPA</th>
	<th style="width: 15px">Rombel Kelas XI IPS</th>
	<th style="width: 15px">Rombel Kelas XI BHS</th>
	<th style="width: 15px">Rombel Kelas XII IPA</th>
	<th style="width: 15px">Rombel Kelas XII IPS</th>
	<th style="width: 15px">Rombel Kelas XII BHS</th>
	</tr></thead>';
echo '</font>';

	$L=1;
	foreach ( $posts as $sekolah) 
	{
		echo "<tr><td><center>".$L++ . " </center></td>
		<td><center>$sekolah->nss</center></td>
		<td>$sekolah->nama_sekolah</td>
		<td>$sekolah->alamat</td>
		<td>$sekolah->status</td>
		<td>$sekolah->desa</td>
		<td>$sekolah->kecamatan</td>
		<td>$sekolah->kode_pos</td>
		<td>$sekolah->kota</td>
		<td>$sekolah->provinsi</td>
		<td>$sekolah->telp</td>
		<td>$sekolah->fax</td>
		<td>$sekolah->email</td>
		<td>$sekolah->website</td>
		<td>$sekolah->kelas_x</td>
		<td>$sekolah->kelas_xi</td>
		<td>$sekolah->kelas_xii</td>
		<td>$sekolah->rombel_x</td>
		<td>$sekolah->rombel_xiipa</td>
		<td>$sekolah->rombel_xiips</td>
		<td>$sekolah->rombel_xibhs</td>
		<td>$sekolah->rombel_xiiipa</td>
		<td>$sekolah->rombel_xiiips</td>
		<td>$sekolah->rombel_xiibhs</td>
		</tr>\n";

}
echo "</table>";

die();
}


function guru_ajax_search_response(){

global $wpdb;
echo '<font size="2">';
$posts = Array();
$findme = $_POST['findme'];
$nama_sekolah = $_POST['nama_sekolah'];
$sql = "SELECT *, sekolah.nama_sekolah from guru INNER JOIN sekolah ON guru.nss=sekolah.nss where nama_guru like '%$findme%' and sekolah.nama_sekolah='$nama_sekolah';";

	$posts = $wpdb->get_results($sql);
	echo '<table class="wp-list-table widefat fixed" >
	<thead><tr>
	<th style="width: 5px">No</th>
	<th style="width: 10px">NUPTK</th>
	<th style="width: 10px">NIP</th>
	<th style="width: 20px">Nama Guru</th>
	<th style="width: 10px">Tempat Lahir</th>
	<th style="width: 10px">Tanggal Lahir</th>
	<th style="width: 10px">Jabatan</th>
	<th style="width: 10px">Pangkat</th>
	<th style="width: 8px">Golongan</th>
	<th style="width: 10px">Status</th>
	<th style="width: 10px">Pendidikan Terakhir</th>
	<th style="width: 10px">Jurusan</th>
	<th style="width: 10px">Mata Pelajaran</th>
	<th style="width: 20px">Jumlah Jam Mata Pelajaran</th>
	<th style="width: 10px">Sertifikat</th>
	<th style="width: 10px">Sertifikat Tahun</th>
	<th style="width: 8px">Ket</th>
	<th style="width: 10px">Nama Sekolah</th>
	</tr></thead>';
	echo '</font>'; 
	$L=1;
	foreach($posts as $guru)
	{
	echo "<tr>
	<td><center>".$L++ . " </center></td>
	<td><center>$guru->nuptk</center></td>
	<td><center>$guru->nip</center></td>
	<td>$guru->nama_guru</td>
	<td>$guru->tempat_lahir</td>
	<td>$guru->tanggal_lahir</td>
	<td>$guru->jabatan</td>
	<td>$guru->pangkat</td>
	<td>$guru->golongan</td>
	<td>$guru->status</td>
	<td>$guru->pendidikan_terakhir</td>
	<td>$guru->jurusan</td>
	<td>$guru->mapel</td>
	<td>$guru->jumlah_jam_mapel</td>
	<td>$guru->sertifikat</td>
	<td>$guru->sertifikat_tahun</td>
	<td>$guru->ket</td>
	<td>$guru->nama_sekolah</td>
	</tr>\n";
}
echo " </table>";

die();
}

?>